rest是否可以使用运行时解析的GenericType参数调用Java JAXRS请求方法?
我想要密码
WebTarget targetBase = ...
targetBase.path("some_path").request(MEDIA_TYPE).get(new GenericType<List<MyModel>>(){});
写下这样的话
public <T> T getViaRest( GenericType<T> myGenericType ) {
return targetBase.path("some_path").request(MEDIA_TYPE).get(myGenericType);
}
...
getViaRest(new GenericType<List<MyModel>>(){});
getViaRest(new GenericType<List<MyModel2>>(){});
...
通过这种方式,我可以有一个通用的getViaRest方法,我可以将自定义日志记录和错误处理代码放入其中,它可以用于我的所有模型
# 1 楼答案
如果要为客户机添加日志记录,可能应该使用客户机请求filter。您可以通过Feature在客户端注册过滤器
例如:
功能(可以在自己的类中提取):
你也可以添加不同的功能,这取决于你想做什么